﻿#ifndef __RANDOM_MAZE_H__
#define __RANDOM_MAZE_H__
#include "../tools/ssCompare.h"
#include "../algorithms/ssSort.h"
#include "../container/ssTDArray.h"

#define MAZE_ROW_MAX	100
#define MAZE_COLUMN_MAX	100

namespace StarSeeker
{

class ssRandomMaze
{
public:
	struct coord_s
	{
		u32 row;
		u32 column;

		coord_s()
		{
			row = 0;
			column = 0;
		}
		coord_s(u32 r, u32 c)
		{
			row = r;
			column = c;
		}
	};

	ssRandomMaze(void);
	~ssRandomMaze(void);

	//建立迷宫
	void Bulid(u32 row, u32 column, coord_s in, coord_s out);
	//查询坐标状态,0不可过，1可过，2出错
	i8 GetCellState(u32 row, u32 column);
	i8 GetCellState(u32 offset);
	//统计有效坐标
	void StatisticPassed();
	//打乱有效坐标
	void RandomPassed();
	//随机一个有效坐标
	coord_s * GetRandomPassed();
	//测试打印
	void PrintCells();
	//获取格子总数
	u32 GetCellCount() {return m_row*m_column;}
private:
	//选邻格
	bool SelectNext(u32 row, u32 column, coord_s &cd);
public:
	ssTDArray<i8>		m_cells;
	u32					m_row;
	u32					m_column;
	coord_s				m_stack[MAZE_ROW_MAX*MAZE_COLUMN_MAX];
	u32					m_numStack;
};

}
#endif
